﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SCResources.BusinissLayer;
using SCResources.General;

namespace Serie_Counter.Presentatie.GuiHelpers
{
    public class UserControlHelper
    {
        private UserControls uC;
        private Panel panelSeries;
        private SelectedCollection selectedCollection;
        private ScResources  manager;
        private updateForm updateForm;
        
        /// <summary>
        /// non default constructor
        /// </summary>
        /// <param name="panelSeries">Panel</param>
        /// <param name="ActiveOrArchive">true: active, false: archived</param>
        /// <param name="manager">SCResources object</param>
        public UserControlHelper(Panel panelSeries, SelectedCollection selectedCollection, ScResources manager, updateForm updateForm)
        {
            this.manager = manager;
            this.selectedCollection = selectedCollection;
            this.panelSeries = panelSeries;
            this.updateForm = updateForm;

        }

        /// <summary>
        /// create usercontrols on a panel
        /// </summary>
        public void createUsercontrols()
        {
            //temp values
            int warningDelay = ScResources.Settings.WarningDelay;
            if (warningDelay < 0) warningDelay = 0;

            //keep track of al userControls
            uC = new UserControls();
            List<Serie> collection;
            if(selectedCollection.Equals(SelectedCollection.Active))
            {
                collection = manager.SerieCollection.ActiveSeries;
            }
            else
            {
                collection = manager.SerieCollection.ArchivedSeries;
            }

            // chang bg of usercontrol if its a download day
            foreach (Serie serie in collection)
            {
                //UserControl UC = new serieUserControl(serie, manager, new reDrawScreen(placeUserControls), updateForm, selectedCollection);
                //if(checkIfAirdate(serie.NextAirDate,warningDelay))
                //{
                //    UC.BackColor = Color.LightGray;
                //}
                //uC.AddControl(UC);
            }
            
        }

        /// <summary>
        /// place usercontrols on panel
        /// </summary>
        public void placeUserControls()
        {
            int UserControlYcO = 0;

            createUsercontrols();
            panelSeries.Controls.Clear();
            foreach (UserControl item in uC.Controls)
            {
                item.Location = new Point(0, UserControlYcO);
                panelSeries.Controls.Add(item);
                UserControlYcO += 75;
            }
            UserControlYcO = 0;

        }

        public bool checkIfAirdate(DateTime date, int delay)
        {
            try
            {
                //with delay (if any)
                if (DateTime.Now.Date.Equals(date.Date.AddDays(delay)))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
